package com.test.designPattern.creationType.singletonPattern;

/**
 * 饿汉单例模式
 *
 * @author wangjie
 * @version V1.0
 * @date 2019/12/14
 */
public class HungrySingletonPattern {
    private static volatile HungrySingletonPattern instance=new HungrySingletonPattern();

    private HungrySingletonPattern(){
        System.out.println(Thread.currentThread().getName()+"\t 构造方法");
    }

    /**
     * @return
     */
    public static HungrySingletonPattern getInstance(){
        return instance;
    }

    public static void main(String[] args) {
        for (int i = 1; i <=10; i++) {
            new Thread(() ->{
                HungrySingletonPattern.getInstance();
            },String.valueOf(i)).start();
        }
    }
}
